package com.ww.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author Administrator
 * @desc ww
 */
@Configuration
public class RabbitHeaderMqConfig {

    /**
     * Header模式
     */
    private static final String HEADER_QUEUE_01 = "header_queue_01";
    private static final String HEADER_QUEUE_02 = "header_queue_02";
    private static final String HEADER_EXCHANGE = "headerExchange";

    @Bean
    public Queue headerQueue01(){
        return new Queue(HEADER_QUEUE_01);
    }
    @Bean
    public Queue headerQueue02(){
        return new Queue(HEADER_QUEUE_02);
    }

    @Bean
    public HeadersExchange headerExchange() {
        return new HeadersExchange(HEADER_EXCHANGE);
    }

    @Bean
    public Binding headerBinding01() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("color", "red");
        map.put("speed", "low");
        return BindingBuilder.bind(headerQueue01()).to(headerExchange()).whereAny(map).match();
    }

    @Bean
    public Binding headerBinding02() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("color", "red");
        map.put("speed", "fast");
        return BindingBuilder.bind(headerQueue02()).to(headerExchange()).whereAll(map).match();
    }


}
